﻿using System;

namespace WXY.Course.Common.MVCExtension
{
    internal class PagerConfig
    {
        //分页的基本属性
        private int currentPage;
        private int pageSize;
        private int recordCount;
        private int pageCount;
        private int pageBarLength;

        internal PagerConfig(PageInfo pageInfo, int pageBarLength)
        {
            this.currentPage = pageInfo.PageNumber;
            this.pageSize = pageInfo.PageSize;
            this.recordCount = pageInfo.RecordCount;
            this.pageCount = (int)Math.Ceiling((double)recordCount / pageSize);
            this.pageBarLength = pageBarLength;
        }

        public bool NeedPage
        {
            get { return pageCount > 1; }
        }

        public int PageCount
        {
            get { return pageCount; }
        }

        public int CurrentPage
        {
            get { return currentPage; }
        }

        public int FirstPage
        {
            get { return 1; }
        }

        public int PrevPage
        {
            get { return currentPage == 1 ? 1 : currentPage - 1; }
        }

        public int NextPage
        {
            get { return currentPage == pageCount ? pageCount : currentPage + 1; }
        }

        public int LastPage
        {
            get { return pageCount; }
        }

        /// <summary>
        /// 分页条长度，为偶数
        /// </summary>
        public int PageBarLength
        {
            get
            {
                if (pageBarLength % 2 > 0) return pageBarLength + 1;
                return pageBarLength;
            }
        }
    }
}